<?php

namespace App\Models;


use App\Models\Concerns\CommentTraits;


/**
 * Class Blog
 * @property integer id
 * @property string title 标题
 * @property string sub_title 副标题
 * @property string content 内容
 * @property string cover 封面图
 * @property string cover_list 列表封面图
 * @property string cover_detail 详情封面图
 * @property boolean status 发布状态
 * @property integer view_count 浏览量
 * @property integer sort 排序
 * @property date start_time 显示开始时间
 * @property date end_time 显示结束时间
 */
class Video extends ApplicationModel
{
    use CommentTraits;
    protected $fillable = [
        'user_id',
        'device_type',
        'device_token',
        'os_version',
        'app_version',
        'theme_id',
        'theme',
        'url',
        'title',
        'content',
        'type',
        'time',
        'size',
        'cover_id',
        'cover',
        'count',
        'like',
        'down',
        'status',
        'fee',
        'hit',
        'hot',
        'sort',
        'theme_sort',
        'sex_label',
        'terror_label',
        'sex_flag',
        'terror_flag',
        'off_type',
        'note',
        'width',
        'height',
        'duration',
        'purchase_id',
        'show_count',
        'score_level',
        'show_score_level',
        'user_type',
        'repost_count',
        'comment_count',




    ];
    const STATUS_RELEASE = 2;//已发布
    const STATUS_OFF = 4;//已下架
    const NOTE_OFF_SEX = '涉黄';
    const NOTE_OFF_TERROR = '暴恐';
    const NOTE_OFF_FORCE = '强制下架';
    const OFF_TYPE_SEX = 1;
    const OFF_TYPE_TERROR = 2;
    const OFF_TYPE_FORCE = 3;
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function like_count()
    {
        return $this->likes()->count();
    }

    public function likes()
    {
        return $this->hasMany(Like::class, 'type_id')->where('type', $this->model_name());
    }

    public function downs()
    {
        return $this->hasMany(Down::class, 'type_id')->where('type', $this->model_name());
    }

    public function down_count()
    {
        return $this->downs()->count();
    }

    public function share_content()
    {
        $cover = $this->cover;
        $do_main = config('constants.DO_MAIN');
        $title = '没想到Ta是这样的大神';
        $content = '“'.$this->user->name.'在CC星球发布了新的视频，快来为ta打call！”';
        $url = $do_main.'/share/index.html?id='.$this->id;
        $arr = array(
            'qqShare' => array('title' => $title, 'content' => $content, 'url' => $url, 'cover' => ($cover ? $cover : 'https://img.superxing.cc/api/img/official_logo.png')),
            'wxShare' => array('title' => $title, 'content' => $content, 'url' => $url, 'cover' => ($cover ? $cover : 'https://img.superxing.cc/api/img/official_logo.png')),
            'wxQuan' => array('title' => $title, 'content' => $content, 'url' => $url, 'cover' => ($cover ? $cover : 'https://img.superxing.cc/api/img/official_logo.png')),
            'wbShare' => array('title' => $title, 'content' => $content, 'url' => $url, 'cover' => ($cover ? $cover : 'https://img.superxing.cc/api/img/official_logo.png')),
            'qqZone' => array('title' => $title, 'content' => $content, 'url' => $url, 'cover' => ($cover ? $cover : 'https://img.superxing.cc/api/img/official_logo.png')),
        );

        return $arr;
    }

    public function send_msg($content, $url)
    {
        //发送推送
        $message = new Message();
        $message->user_id = $this->user_id;
        $message->content = $content;
        $message->icon = Message::ICON;
        $message->url_schema = $url;
        $message->type_id = $this->id;
        $message->save();

        $message->pushMsg($this->user_id, $content, "{'url':'" . $url . "'}");
    }

}
